package com.fortune.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.fortune.vo.mSelect.ProductDisc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fortune.dao.MProductInfoDao;
import com.fortune.dao.MStoreDao;
import com.fortune.service.MSelectService;
import com.fortune.vo.mSelect.SelectProduct;
import com.fortune.vo.mSelect.SelectStore;
import com.fortune.vo.mStoreInit.MInitStoreName;
@Service
public class MSelectServiceImpl implements MSelectService {
	@Autowired
	private MProductInfoDao mProductInfoDao;
	@Autowired
	private MStoreDao mStoreDao;
	@Override
	public List<SelectProduct> listAllMProducts(String mId, String dId) {
		List<SelectProduct> list = mProductInfoDao.listSelectProductsByMIdAndDId(mId, dId);
		return list;
	}

	@Override
	public List<SelectProduct> listAllMProductss(String mId, String dId, Integer type) {
		List<SelectProduct> list = mProductInfoDao.listSelectProductsByMIdAndDIds(mId, dId,type);
		for(SelectProduct selectProduct:list){
			if(selectProduct.getPrice().equals(BigDecimal.ZERO)){
				SelectProduct who = mProductInfoDao.findWhoPrice(mId,selectProduct.getId());
				selectProduct.setPrice(who.getWhoPrice());
			}
		}
		return list;
	}

	@Override
	public List<SelectStore> listAllMStores(String mId) {
		List<MInitStoreName> stores = mStoreDao.queryStoreNameList(mId);
		List<SelectStore> selectStores = new ArrayList<>();
		for (MInitStoreName store : stores) {
			SelectStore selectStore = new SelectStore();
			selectStore.setId(store.getId());
			selectStore.setName(store.getName());
			selectStores.add(selectStore);
		}
		return selectStores;
	}

	@Override
	public ProductDisc findProDisc(String mid,String proId) {
		ProductDisc disc =  mStoreDao.findProDisc(mid,proId);
		return disc;
	}

}
